#include<iostream>
using namespace std;
class CMoney
{
private:
    int yuan, jiao, fen;
public:
    CMoney(int y = 0, int j = 0, int f = 0)
    {
        yuan = y;
        jiao = j;
        fen = f;
    }
    CMoney operator+(const CMoney& a)
    {
        CMoney ans;
        ans.fen = fen + a.fen;
        ans.jiao = jiao + a.jiao;
        ans.yuan = yuan + a.yuan;
        if (ans.fen >= 10)
        {
            ans.jiao = ans.jiao + (ans.fen / 10);
            ans.fen %= 10;
        }
        if (ans.jiao >= 10)
        {
            ans.yuan = ans.yuan + (ans.jiao / 10);
            ans.jiao %= 10;
        }
        return ans;
    }
    CMoney operator-(const CMoney& a)
    {
        CMoney ans;
        ans.fen = fen - a.fen;
        ans.jiao = jiao - a.jiao;
        ans.yuan = yuan - a.yuan;
        if (ans.fen < 0)
        {
            ans.jiao -= 1;
            ans.fen += 10;
        }
        if (ans.jiao < 0)
        {
            ans.yuan -= 1;
            ans.jiao += 10;
        }
        return ans;
    }
    friend ostream& operator<<(ostream& os, const CMoney& a);
    friend istream& operator>>(istream& is, CMoney& a);
};
ostream& operator<<(ostream& os, const CMoney& a)
{
    os << a.yuan << "元" << a.jiao << "角" << a.fen << "分";
    return os;
}
istream& operator>>(istream& is, CMoney& a)
{
    int x, y, z;
    is >> x >> y >> z;
    a.yuan = x;
    a.jiao = y;
    a.fen = z;
    return is;
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        CMoney ans, tmp;
        cin >> ans;
        string cmd;
        cin >> cmd;
        while (cmd != "stop")
        {
            cin >> tmp;
            if (cmd == "add")
            {
                ans = ans + tmp;
            }
            else if (cmd == "minus")
            {
                ans = ans - tmp;
            }
            cin >> cmd;
        }
        cout << ans << endl;
    }
}